package com.zhang;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhang.domain.User;
import com.zhang.mapper.UserMapper;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.ArrayList;
import java.util.HashMap;

@SpringBootTest
public class Delete {



    @Autowired
    private UserMapper userMapper;

    //1.根据Id 删除(单个)
    @Test
    public void test1() {
        userMapper.deleteById(1);
    }


    //2.根据Id集合 删除(多个)
    @Test
    public void test2() {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(6);
        list.add(7);
        userMapper.deleteBatchIds(list);
    }


    //3.根据条件构造器 删除(多个)
    @Test
    public void test3() {
        //1.条件
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("username","刘备");

        //2.删除
        userMapper.delete(wrapper);
    }
    //3.根据条件构造器 删除(全部)
    @Test
    public void test4() {
        //1.条件
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("1","1");

        //2.删除
        userMapper.delete(wrapper);
    }


    //4.根据Map<String,Object> 删除(多个)
    @Test
    public void test5() {
        HashMap<String, Object> map = new HashMap<>();
        map.put("username","张飞");
        map.put("username","赵云"); //它只会删除所有名字叫赵云的,张飞一个也不删除
        userMapper.deleteByMap(map);
    }


}
